<template>
  <div class="iconbox" >
    <div class="qiye" v-if="isshow">
    <i class="el-icon-edit" @click="editNews"></i>
     <div class="check" v-if="flag">
    <el-tooltip class="item" effect="dark" content="启用" placement="top">
      <i class="el-icon-check"  @click="changeState('启用')"></i>
    </el-tooltip>
     </div>
        <div class="close" v-else>
     <el-tooltip class="item" effect="dark" content="禁用" placement="top">
     <i class="el-icon-close"  @click="changeState('close')"></i>
    </el-tooltip>
    </div>
    <i class="el-icon-delete" @click="deleteNews" ></i>

    </div>
    <div class="question" v-if="show">
   <i class="el-icon-view" @click="readerNews"></i>
   <i class="el-icon-edit" @click="editNews"></i>
   <i class="el-icon-delete" @click="deleteNews"></i>
  <i class="el-icon-check"  @click="changeType"></i>
    </div>
   </div>
</template>

<script>
export default {
  name: 'operate',
  props: {
    row: {
      type: Object,
      default: () => ({})
    },
    isshow: {
      type: Boolean,
      default: false
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      flag: null
    }
  },
  created () {
    if (this.row.state === '启用') {
      this.flag = false
    } else {
      this.flag = true
    }
  },
  methods: {
    editNews () {
      this.$emit('editNews', this.row.id)
    },
    changeState (type) {
      if (type === 'close') {
        this.$confirm('已成功禁用', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '禁用成功!'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        this.$confirm('已成功启用', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '启用成功!'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      }
      this.flag = !this.flag
      const obj = { state: this.flag ? 0 : 1, id: this.row.id }
      this.$emit('changeState', obj)
    },
    deleteNews () {
      this.$emit('deleteNews', this.row.id)
    },
    readerNews () {
      this.$emit('readerNews', this.row.id)
    },
    changeType () {
      this.$emit('changeType', this.row.id)
    }
  }
}
</script>

<style scoped lang='less'>
.iconbox{
  display: flex;
  .qiye{
    display: flex;
  }
  .question{
    display: flex;
  }
  i{
    margin-right: 5px;
  }
}
.el-icon-edit {
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #ecf5ff;
  color: #409eff;
  line-height: 37px;
  text-align: center;
}
.el-icon-edit:hover{
  background-color:#409eff ;
  color: #fff;
}
.el-icon-delete {
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #fef0f0;
  color: #f56c6c;
  line-height: 37px;
  text-align: center;
}
.el-icon-delete:hover{
  background-color: #f56c6c;
  color: #fff;
}
.el-icon-check{
    width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #f0f9eb;
  color: #67c23a;
  line-height: 37px;
  text-align: center;
}
.el-icon-check:hover{
  background-color: #67c23a;
  color: #fff;
}
.el-icon-close{
    width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #fdf6ec;
  color: #e6a23c;
  line-height: 37px;
  text-align: center;
}
.el-icon-close:hover{
  background-color:#e6a23c;
  color: #fff;
}
  .item {
      width: 37px;
      height: 37px;
    }
    .check{
         width: 37px;
      height: 37px;
    }
    .close{
         width: 37px;
      height: 37px;
    }
.el-icon-view{
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #fdf6ec;
  color: #e6a23c;
  line-height: 37px;
  text-align: center;
}
.el-icon-view:hover{
  background-color:  #e6a23c;
   color: #fff;
}
</style>
